package com.moyq5.permit.center.core.dao.impl;


import java.util.ArrayList;
import java.util.List;

import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.stereotype.Repository;

import com.moyq5.mvc.framework.dao.BasicDao;
import com.moyq5.mvc.framework.dao.ExampleQuery;
import com.moyq5.permit.center.bean.entity.SysRole;
import com.moyq5.permit.center.bean.entity.SysRole_;
import com.moyq5.permit.center.bean.search.SysRole4Search;
import com.moyq5.permit.center.core.dao.SysRoleDao;


/**
 * @author Moyq5's MvcMaker Tools
 */
@Repository
public class SysRoleDaoImpl extends BasicDao<SysRole, SysRole4Search> implements SysRoleDao {

	public SysRoleDaoImpl() {
		super(SysRole.class);
	}

	@Override
	protected CriteriaQuery<SysRole> createSearchCriteria(ExampleQuery<SysRole> eq, SysRole4Search t4s) {
		CriteriaQuery<SysRole> cq = eq.getCriteriaQuery();
		
		@SuppressWarnings("unchecked")
		Root<SysRole> cr = (Root<SysRole>) cq.getRoots().iterator().next();
		List<Predicate> ps = new ArrayList<Predicate>();
		ps.add(cq.getRestriction());
		
		if (null != t4s.getRoleIdIn()) {
			ps.add(cr.get(SysRole_.roleId).in(t4s.getRoleIdIn()));
		}
		// TODO 在这里实现其它属性（条件）的查询
		
		cq.where(ps.toArray(new Predicate[ps.size()]));
		
		return cq;
	}

}

